package cn.hy.preparelesson.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * url相关utils
 */
public class UrlUtils {

    /**
     * 获取url参数
     * @param url
     * @return
     */
    public static Map<String, String> getUrlParamMap(String url) {
        if (StringUtils.isBlank(url) || !url.contains("?")) {
            return null;
        }
        String[] urlParts = url.split("\\?");
        if (urlParts.length == 1) {
            return null;
        }
        //有参数
        String[] params = urlParts[1].split("&");
        Map<String, String> paramMap = new HashMap<>();
        for (String param : params) {
            String[] keyValue = param.split("=");
            paramMap.put(keyValue[0], keyValue.length > 1 ?  keyValue[1] : "");
        }
        return paramMap;
    }

}
